package TrainModel;

import java.util.LinkedList;
import java.util.Queue;

import Utilities.Message;
import Utilities.logFileIO;


public class CommunicationModule
{
	//private Message localMessage;
	private Queue<Message> mQueue;
	private boolean bSignalPickupFail;
	private int iTrainID;
	private logFileIO logFile;
	
	public CommunicationModule( logFileIO lf, int tID )
	{
		logFile = lf;
		iTrainID = tID;
		logFile.write("Train " + iTrainID + ": CommMod: I am a Communication Module!");
		bSignalPickupFail = false;
		mQueue = new LinkedList<Message>();
	}
	
	public void recieveMessage( Message m )
	{
		if(!bSignalPickupFail && m != null)
		{
			mQueue.add(m);
			logFile.write("Train " + iTrainID + ": CommMod: Received a message!");
		}
	}
	
	public Message getMessage()
	{
		Message messToPass = mQueue.poll();
		logFile.write("Train " + iTrainID + ": CommMod: Passed a message on!");
		return messToPass;
	}
	
	public void setSignalPickupFailure( boolean f )
	{
		logFile.write("Train " + iTrainID + ": CommMod: Setting Pickup Failure to: "+ f + "!");
		bSignalPickupFail = f;
	}
	
	public boolean getSignalPickupFailure()
	{
		return this.bSignalPickupFail;
	}
}
